package com.zg.scf.service.impl;


import com.alibaba.excel.EasyExcel;
import com.zg.common.core.dao.scf.PortPlanDao;
import com.zg.common.core.dao.scf.entity.PortPlan;
import com.zg.common.core.service.PageBaseService;
import com.zg.scf.service.PortPlanService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

/**
 * <p>Description: </p>
 *
 * @author zhanfeng.liang
 * @since 2025/5/22 10:47
 */



@Service
@Slf4j
public class PortPlanServiceImpl extends PageBaseService<PortPlan, PortPlanDao> implements PortPlanService {


    @Override
    public String importExcel(MultipartFile file) {
        List<PortPlan> dataList = null;
        try {
            dataList = EasyExcel.read(file.getInputStream())
                    .head(PortPlan.class)
                    .sheet()
                    .doReadSync();
            if (!dataList.isEmpty()) {
                baseDao.saveBatch(dataList);
                return "导入成功，共导入" + dataList.size() + "条数据";
            }
        } catch (IOException e) {
            log.error("导入失败", e);
            return "导入失败:"+e.getMessage();
        }
        return null;
    }


    
}
